<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class user_model extends CI_Model {

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
	function insertUser($user){
        $this->db->insert('user', $user);
        return $this->db->insert_id();     
    }
	function getAllOfUser(){
         $query = $this->db->get('users');
        if($query->num_rows() > 0) return $query->result();
        return false;                
    }
    function getUserByUserName($username){
         $this->db->select('users.*');
         $this->db->from('users');
         $this->db->where('users.user_name', $username);
         $query = $this->db->get();
        if($query->num_rows() == 1){
            return $query->row_array();
        }else{
            return false;
        }
    }
    function getUserById($userId){
    	 $this->db->select('users.*');
         $this->db->from('users');
         $this->db->where('users.id', $userId);
         $query = $this->db->get();
        if($query->num_rows() == 1){
            return $query->row_array();
        }else{
            return false;
        }
    }
   function updateUser($username,$user){
        $this->db->where('user_name', $username);
        $this->db->update('users', $user); 
    }
    function inserImage($image){
    	$this->db->insert('photo', $image);
        return $this->db->insert_id();  
    }
    function deleteFile($fileId){
        $this->db->delete('photo', array('id' => $fileId)); 
    }
    function updateAutNew($id,$content){
    	$this->db->where('id', $id);
        $this->db->update('aut_new', $content);   	
    }
    function updateWeather($id,$content){
    	$this->db->where('id', $id);
        $this->db->update('weather', $content);   	
    }
	function updateAutLibrary($id,$content){
    	$this->db->where('id', $id);
        $this->db->update('aut_library', $content);   	
    }
    function getAllWeather(){
    	$query = $this->db->get('weather');
        if($query->num_rows() > 0) return $query->result();
        return false;
    }
    function getAllAutNew(){
    	$query = $this->db->get('aut_new');
        if($query->num_rows() > 0) return $query->result();
        return false;  	
    }
    function getAllAutLibrary(){
    	$query = $this->db->get('aut_library');
        if($query->num_rows() > 0) return $query->result();
        return false;  	
    }
 	function updateConfigLength($configId,$value)
    {
    	$this->db->where("id",$configId);
    	$this->db->update("config_setting",$value);
    }
    
    function updateCurrentTravel($value){
		$this->db->where("type","travel");
    	$this->db->update("temp",$value);
    }
    
	function updateCurrentClass($value){
		$this->db->where("type","class");
    	$this->db->update("temp",$value);
    }
}